import { createContext } from "react";
import { IGlobalConfig, IPhotoData } from "../type";
import { defaultGlobalConfig } from "../config";

interface IIndexContext {
  showPhotoIndex: number; // 当前显示的图片下标
  showPhoto?: IPhotoData; // 当前显示的图片
  setShowPhotoIndex: React.Dispatch<React.SetStateAction<number >>; // 设置当前显示的图片
  photoList: IPhotoData[]; // 照片列表数据
  setPhotoList: React.Dispatch<React.SetStateAction<IPhotoData[]>>; // 设置图片列表数据
  globalConfig: IGlobalConfig; // 全局配置
  setGlobalConfig: React.Dispatch<React.SetStateAction<IGlobalConfig>>; // 设置图片列表数据
  reRenderCanvas: (photoInfo: IPhotoData) => void; // 重绘画布
}

const defaultValue = {
  showPhotoIndex: 0,
  globalConfig: defaultGlobalConfig,
  photoList: [],
  setPhotoList: () => {},
  setShowPhotoIndex: () => {},
  setGlobalConfig: () => {},
  reRenderCanvas: () => {},
};

const indexContext = createContext<IIndexContext>(defaultValue);

export type { IIndexContext };
export default indexContext;
